package com.tarena.lbs.content.utils;

import org.springframework.cglib.core.Converter;
import org.springframework.stereotype.Component;

@Component
public class StringToIntegerSafeConverter implements Converter {
    @Override
    public Object convert(Object value, Class target, Object context) {
        return null;
    }


    public Integer convert(String source) throws IllegalAccessException {
        if(source ==null || source.trim().isEmpty()){
            return null;
        }
        try {
            return Integer.valueOf(source);
        }catch (NumberFormatException e){
            throw  new IllegalAccessException("无法将 '" + source + "' 转换为整数");
        }
    }
}
